/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.icanci.loopstack.damc.admin.biz.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.icanci.loopstack.damc.admin.biz.mapper.DisposableScriptMapper;
import cn.icanci.loopstack.damc.admin.biz.service.DisposableScriptService;
import cn.icanci.loopstack.damc.admin.common.model.base.DisposableScriptVO;
import cn.icanci.loopstack.damc.admin.dal.common.PageList;
import cn.icanci.loopstack.damc.admin.dal.mongo.daointerface.DisposableScriptDAO;
import cn.icanci.loopstack.damc.admin.dal.mongo.dateobject.DisposableScriptDO;

/**
 * @author icanci
 * @since 1.0 Created in 2025/05/26 20:53
 */
@Service("disposableScriptService")
public class DisposableScriptServiceImpl implements DisposableScriptService {
    @Resource
    private DisposableScriptDAO    disposableScriptDAO;
    @Resource
    private DisposableScriptMapper disposableScriptMapper;

    /**
     * 查询所有 T
     *
     * @return 返回所有T
     */
    @Override
    public List<DisposableScriptVO> queryAll() {
        return disposableScriptMapper.dos2vos(disposableScriptDAO.queryAll());
    }

    /**
     * 保存或者更新一条信息
     *
     * @param disposableScriptVO t
     */
    @Override
    public void save(DisposableScriptVO disposableScriptVO) {
        if (doInsert(disposableScriptVO)) {
            DisposableScriptDO insert = disposableScriptMapper.vo2do(disposableScriptVO);
            disposableScriptDAO.insert(insert);
        } else {
            disposableScriptDAO.update(disposableScriptMapper.vo2do(disposableScriptVO));
        }
    }

    /**
     * 根据id进行查询
     *
     * @param id id
     * @return 返回查询的结果
     */
    @Override
    public DisposableScriptVO queryById(String id) {
        return disposableScriptMapper.do2vo(disposableScriptDAO.queryOneById(id));
    }

    /**
     * 分页查询
     *
     * @param disposableScriptVO T
     * @param pageNum            pageNum
     * @param pageSize           pageSize
     * @return 返回分页查询结果
     */
    @Override
    public PageList<DisposableScriptVO> queryPage(DisposableScriptVO disposableScriptVO, int pageNum, int pageSize) {
        PageList<DisposableScriptDO> pageQuery = disposableScriptDAO.pageQuery(disposableScriptMapper.vo2do(disposableScriptVO), pageNum, pageSize);
        return new PageList<>(disposableScriptMapper.dos2vos(pageQuery.getData()), pageQuery.getPaginator());
    }

    /**
     * 根据id删除配置[物理删除]
     *
     * @param id id
     */
    @Override
    public void deleteById(String id) {
        disposableScriptDAO.deleteById(id);
    }
}
